package com.binvshe.binvshe.organization.orgtype;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.binvshe.binvshe.common.http.ListDataRequestListener;
import com.binvshe.binvshe.common.http.MyHttpRequest;
import com.binvshe.binvshe.common.http.UrlCenter;
import com.binvshe.binvshe.organization.entity.OrgTypeEntity;
import com.pachong.android.baseuicomponent.CompState;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;
import com.pachong.android.baseuicomponent.fragment.SwipeListFragment;
import com.pachong.android.framework.httprequest.IHttpRequest;
import com.pachong.android.framework.httprequest.UrlParams;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/8
 */
public class SelectTypeFragment extends SwipeListFragment {


    public static SelectTypeFragment newInstance() {
        Bundle args = new Bundle();
        SelectTypeFragment fragment = new SelectTypeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        clearDecorations();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        onStartLoading();
    }

    @Override
    public RecyclerViewBaseAdapter createAdapter() {
        return new OrgTypeAdapter(getContext());
    }

    @Override
    public void onStartLoading() {
        getOrgType();
        getAdapter().notifyDataSetChanged();
    }

    public int getSelectTypeID() {
        return ((OrgTypeAdapter) getAdapter()).getSelectTypeID();
    }

    @Override
    public void onStartRefreshing() {
        super.onStartRefreshing();
        getData().clear();
        onStartLoading();
    }

    private ListDataRequestListener<OrgTypeEntity> mResponceListener = new ListDataRequestListener(this, OrgTypeEntity.class , true);

    /**
     * 获取可选的类型
     */
    private void getOrgType() {
        IHttpRequest request = new MyHttpRequest(getContext());
        request.get(UrlCenter.GET_ORG_TYPE, null, mResponceListener);
    }

}
